﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2013/11/5 星期二 0:00:44
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Sector7.Framework.Drivers.RF
{
    /// <summary>
    /// IC卡读卡器基类
    /// </summary>
    [Serializable()]
    [DataContract]
    public abstract class RfReaderBase : IRfReaderBase
    {
        #region Accessor
        /// <summary>
        /// 获取设备序列号
        /// </summary>
        public string SerialNumber
        {
            get { return m_serialNumber; }
        }
        #endregion

        #region Public functions
        public abstract int Initialize(short port, int baud);
        public abstract int LoadPassword(int keysetMode, int sectorNumber, string password);
        public abstract int SearchCard(int searchMode);
        public abstract int ReleaseCard();
        public abstract int ReadData(int address, byte[] data);
        public abstract int WriteData(int address, byte[] data);
        public abstract void Dispose();
        public abstract int Beep(int duration);

        public string GetSerialNumber()
        {
            return SerialNumber;
        }
        #endregion

        #region Private functions
        /// <summary>
        /// 生成错误码
        /// </summary>
        /// <returns>操作错误码</returns>
        protected abstract int GenerateFaultId();
        #endregion

        #region Structure
        #endregion

        #region Inner memeber
        /// <summary>
        /// 操作结果
        /// </summary>
        protected int m_result = RfReader_ErrorCode.ERR_RF_SUCCESS;

        /// <summary>
        /// 串口号
        /// </summary>
        protected short m_port = -1;

        /// <summary>
        /// 通讯波特率
        /// </summary>
        protected int m_baud = -1;

        /// <summary>
        /// 设备句柄
        /// </summary>
        protected int m_handle = -1;

        /// <summary>
        /// 扇区号
        /// </summary>
        protected int m_sectorNumber = 0;

        /// <summary>
        /// 密码验证模式
        /// </summary>
        protected int m_keyMode = KEY_MODE_DEFAULT;

        /// <summary>
        /// 设备序列号
        /// </summary>
        protected string m_serialNumber = string.Empty;

        /// <summary>
        /// 操作成功报警持续时间（毫秒）
        /// </summary>
        public const int BEEP_DURATION_SUCCESS = 10;

        /// <summary>
        /// 操作失败报警持续时间（毫秒）
        /// </summary>
        public const int BEEP_DURATION_FAILURE = 30;

        /// <summary>
        /// 默认搜索卡片模式
        /// </summary>
        public const int SEARCH_MODE_DEFAULT = 0;

        /// <summary>
        /// 默认密码验证模式
        /// </summary>
        public const int KEY_MODE_DEFAULT = 0;
        #endregion
    }
}
